﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Channels;
using System.ComponentModel;

using MichaelKappel.Net.HelloWorld.NetNamedPipeBinding.Interfaces;

namespace MichaelKappel.Net.HelloWorld.NetNamedPipeBinding
{
    public class TestNotify : INotifyPropertyChanged
    {
        public static TestNotify Instance = new TestNotify();
        private DateTime lastReadDate = default(DateTime);
        public DateTime LastReadDate
        {
            get
            {
                return lastReadDate;
            }
            set
            {
                lastReadDate = value;
                OnPropertyChanged("LastReadDate");
            }
        }
        private String lastReadBy = null;
        public String LastReadBy
        {
            get
            {
                return lastReadBy;
            }
            set
            {
                lastReadBy = value;
                OnPropertyChanged("LastReadBy");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }
    }
    
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class TestService : ITestService
    {
        public Boolean Test(String name)
        {
            TestNotify.Instance.LastReadDate = DateTime.Now;
            TestNotify.Instance.LastReadBy = name;
            return true;
        }
    }
}
